package com.infore.airsupervise.ui.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.LawingSiteE;
import com.infore.airsupervise.bean.UserE;
import com.infore.airsupervise.other.listener.LayoutControl;
import com.infore.airsupervise.other.listener.LayoutControlListener;
import com.infore.airsupervise.ui.activity.SitePartDetailActivity;
import com.infore.airsupervise.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 执法台账 检查记录
 * Created by xiaotao on 2017/5/31.
 */

public class SiteRecordDetailFragment extends BaseFragment {
    @BindView(R.id.tv_info_arrow)
    AwesomeTextView tvInfoArrow;
    @BindView(R.id.tv_source)
    TextView tvSource;
    @BindView(R.id.tv_permit)
    TextView tvPermit;
    @BindView(R.id.tv_wasteLicence)
    TextView tvWasteLicence;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_corporate)
    TextView tvCorporate;
    @BindView(R.id.tv_leader_name)
    TextView tvLeaderName;
    @BindView(R.id.tv_position)
    TextView tvPosition;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_checkContent)
    TextView tvCheckContent;
    @BindView(R.id.tv_recordPsons)
    TextView tvRecordPsons;
    @BindView(R.id.tl_info)
    TableLayout tlInfo;
    @BindView(R.id.tv_condition_arrow)
    AwesomeTextView tvConditionArrow;
    @BindView(R.id.tv_produceStatus)
    TextView tvProduceStatus;
    @BindView(R.id.tv_examineFail)
    TextView tvExamineFail;
    @BindView(R.id.threeTogether)
    TextView threeTogether;
    @BindView(R.id.buildAndAccept)
    TextView buildAndAccept;
    @BindView(R.id.systemInstall)
    TextView systemInstall;
    @BindView(R.id.systemOperate)
    TextView systemOperate;
    @BindView(R.id.systemInternet)
    TextView systemInternet;
    @BindView(R.id.systemAccept)
    TextView systemAccept;
    @BindView(R.id.onlineData)
    TextView onlineData;
    @BindView(R.id.tv_waterLet)
    TextView tvWaterLet;
    @BindView(R.id.tv_airLet)
    TextView tvAirLet;
    @BindView(R.id.defaultWaste)
    TextView defaultWaste;
    @BindView(R.id.defaultTransfer)
    TextView defaultTransfer;
    @BindView(R.id.dangerWaste)
    TextView dangerWaste;
    @BindView(R.id.dangerTransfer)
    TextView dangerTransfer;
    @BindView(R.id.toteOffice)
    TextView toteOffice;
    @BindView(R.id.wasteLedger)
    TextView wasteLedger;
    @BindView(R.id.emergencyCase)
    TextView emergencyCase;
    @BindView(R.id.conclusion)
    TextView conclusion;
    @BindView(R.id.detailRequire)
    TextView detailRequire;
    @BindView(R.id.ll_condition)
    LinearLayout llCondition;
    Unbinder unbinder;
    private SitePartDetailActivity parent;
    private LawingSiteE.RecorderJC record;
    private LayoutControlListener layoutControl;

    public SiteRecordDetailFragment() {
    }

    @SuppressLint("ValidFragment")
    public SiteRecordDetailFragment(Object result) {
        record = (LawingSiteE.RecorderJC) result;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_site_record_detail, container, false);
        unbinder = ButterKnife.bind(this, view);
        parent = (SitePartDetailActivity) getActivity();
        layoutControl = new LayoutControl(parent);
        setRecordData();
        return view;
    }

    private void setRecordData(){
        if(null == record ){
            ToastUtil.showShort(parent,"该数据为空");
            return ;
        }
        tvWasteLicence.setText(record.getWasteLicence());
        tvLeaderName.setText(record.getLeaderName());
        tvPhone.setText(record.getLeaderPhone());
        tvPosition.setText(record.getLeaderPosition());
        tvCheckContent.setText(record.getSupervise());
        tvProduceStatus.setText(record.getProduceStatus());
        tvExamineFail.setText(record.getExamineFail());
        threeTogether.setText(record.getThreeTogether());
        buildAndAccept.setText(record.getBuildAndAccept());
        systemInstall.setText(record.getSystemInstall());
        systemOperate.setText(record.getSystemOperate());
        systemInternet.setText(record.getSystemInternet());
        systemAccept.setText(record.getSystemAccept());
        onlineData.setText(record.getOnlineData());
        tvWaterLet.setText(record.getWaterLet());
        tvAirLet.setText(record.getAirLet());
        defaultWaste.setText(record.getDefaultWaste());
        defaultTransfer.setText(record.getDefaultTransfer());
        dangerTransfer.setText(record.getDangerTransfer());
        dangerWaste.setText(record.getDangerWaste());
        emergencyCase.setText(record.getEmergencyCase());
        toteOffice.setText(record.getToteOffice());
        wasteLedger.setText(record.getWasteLedger());
        detailRequire.setText(record.getDetailRequire());
        conclusion.setText(record.getConclusion());
        //执法人
        if(null != record.getInspectPson() && record.getInspectPson().size() > 0){
            StringBuffer str_notePson = new StringBuffer();
            for(UserE userE : record.getInspectPson()){
                str_notePson.append(userE.getRealName())
                        .append(",");
            }
            str_notePson.deleteCharAt(str_notePson.length()-1);
            tvRecordPsons.setText(str_notePson);
        }

    }





    boolean isInfoShow;
    boolean isConditionShow;
    @OnClick({R.id.ll_info_control, R.id.ll_condition_control})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_info_control:
                isInfoShow = !isInfoShow;
                layoutControl.layoutControl(isInfoShow,tlInfo,tvInfoArrow);
                break;
            case R.id.ll_condition_control:
                isConditionShow = !isConditionShow;
                layoutControl.layoutControl(isConditionShow,llCondition,tvConditionArrow);
                break;
        }
    }
}
